using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class pages_PersonalInfoControl : System.Web.UI.UserControl
{
    Person person = new Person();
    protected void Page_Load(object sender, EventArgs e)
    {       
          

    }
    public void LoadData()
    {
        Util util = new Util();
        User user = Session["user"] as User;
        if (user == null) return;
        person = user.PersonInfor;        
        cmbCountry.DataSource = util.GetCountryList();
        cmbCountry.DataBind();    
        txtFirstName.Text = person.FirstName;
        txtLastName.Text = person.LastName;
        txtDateOfBirth.Text = person.DateOfBirth.ToShortDateString();
        radMale.Checked = person.Gender;
        radFemale.Checked = !person.Gender;
        txtEmail.Text = person.Email;
        txtPhone.Text = person.Phone;
        txtState.Text = person.State;
        txtCity.Text = person.City;
        txtAddress.Text = person.Address;
        if (person.Country != "")
        {
            int index = 0;
            foreach (ListItem item in cmbCountry.Items)
            {
                if (person.Country == item.Text)
                {
                    cmbCountry.SelectedIndex = index;
                    break;
                }
                index++;
            }
        }
    }
 
    #region Propreties
    public string FirstName
    {
        get { return txtFirstName.Text; }        
    }
    public string LastName
    {
        get { return txtLastName.Text; }      
    }
    public DateTime DateOfBirth
    {
        get {
            try
            {
                return DateTime.Parse(txtDateOfBirth.Text);
            }
            catch (Exception ex)
            {
                return DateTime.MinValue;
            }         
        }       
    }
    public bool Gender
    {
        get { return radMale.Checked; }        
    }
    public string Address
    {
        get { return txtAddress.Text; }      
    }
    public string Country
    {
        get {
            if(cmbCountry.SelectedIndex>-1)return cmbCountry.SelectedItem.Text;
            return "";
        }        
    }
    public string State
    {
        get { return txtState.Text; }       
    }
    public string City
    {
        get { return txtCity.Text; }        
    }
    public string Email
    {
        get { return txtEmail.Text; }       

    }
    public string Phone
    {
        get { return txtPhone.Text; }      
    }
    public Person PersonInfoObject
    {
        get { return person; }
        
    }
    #endregion
}
